package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.TransportPurchase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * created by wangjunfu on 2021-02-24 15:59:47
 */
@Repository
public class TransportPurchaseDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(TransportPurchaseDao.class);

    public TransportPurchase insert(final TransportPurchase transportPurchase) {
        insert("TransportPurchase.insert", transportPurchase);
        return transportPurchase;
    }

    public Boolean updateInfoById(final TransportPurchase transportPurchase) {
        return update("TransportPurchase.updateInfoById", transportPurchase) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("TransportPurchase.updateInfoByQuery", query) > 0;
    }

    public TransportPurchase selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("TransportPurchase.selectById", query);
    }

    public List<TransportPurchase> selectByQuery(final Query query) {
        return queryForList("TransportPurchase.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("TransportPurchase.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        TransportPurchase transportPurchase = new TransportPurchase();
        transportPurchase.setDeleteFlag(1);
        transportPurchase.setId(id);
        transportPurchase.setEntId(entId);

        return update("TransportPurchase.updateInfoById", transportPurchase) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("TransportPurchase.deleteById", query) > 0;
    }

    //模糊搜索物料
    public List<Map<String, String>> selectSimilarPurchase(final Query query) {
        List<Map<String, String>> map = queryForList("TransportPurchase.selectSimilarPurchase", query);
        return map;
    }
}